package com.repository.common;

import com.repository.enums.*;
import com.repository.enums.ResultCode;
import lombok.Data;

/**
 * @program: jc-club
 * @description: 返回类
 * @author: 张继成
 * @create: 2024-03-18 22:44
 **/
@Data
public class Result<T> {
    private Boolean success;

    private Integer code;

    private  String message;

    private T data;

    public static Result ok(){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getDesc());
        return result;
    }

    public static<T> Result ok(T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getDesc());
        result.setData(data);
        return result;
    }

    public static Result fali(){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.FAIL.getCode());
        result.setMessage(ResultCode.FAIL.getDesc());
        return result;
    }

    public static<T> Result fali(T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.FAIL.getCode());
        result.setMessage(ResultCode.FAIL.getDesc());
        return result;
    }
}
